using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VDRBPOS
    {
        public DataRow Convert2DRBPOS(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryDRBPOS(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["DRBPMANDANT"] = " ".PadRight(2 ); 
         dwReturn["DRBPLFDNR"] = " ".PadRight(4 ); 
         dwReturn["DRBPPOS"] = " ".PadRight(4 ); 
         dwReturn["DRBPBEZ"] = " ".PadRight(64 ); 
         dwReturn["DRBPPROG1"] = " ".PadRight(64 ); 
         dwReturn["DRBPPROG2"] = " ".PadRight(64 ); 
         dwReturn["DRBPDRBENID"] = " ".PadRight(8 ); 
         dwReturn["DRBPDRAUFTR"] = " ".PadRight(4 ); 
         dwReturn["DRBPAUFBENID"] = " ".PadRight(8 ); 
         dwReturn["DRBPLASTAUF"] = " ".PadRight(4 ); 
         dwReturn["DRBPABHLFDNR1"] = " ".PadRight(0 ); 
         dwReturn["DRBPABHPOS1"] = " ".PadRight(0 ); 
         dwReturn["DRBPABHLFDNR2"] = " ".PadRight(0 ); 
         dwReturn["DRBPABHPOS2"] = " ".PadRight(0 ); 
         dwReturn["DRBPABHLFDNR3"] = " ".PadRight(0 ); 
         dwReturn["DRBPABHPOS3"] = " ".PadRight(0 ); 
         dwReturn["DRBPABHLFDNR4"] = " ".PadRight(0 ); 
         dwReturn["DRBPABHPOS4"] = " ".PadRight(0 ); 
         dwReturn["DRBPABHLFDNR5"] = " ".PadRight(0 ); 
         dwReturn["DRBPABHPOS5"] = " ".PadRight(0 ); 
         dwReturn["DRBPLSTARTD"] = " ".PadRight(0 ); 
         dwReturn["DRBPLSTARTZ"] = " ".PadRight(0 ); 
         dwReturn["DRBPLENDED"] = " ".PadRight(0 ); 
         dwReturn["DRBPLENDEZ"] = " ".PadRight(0 ); 
         dwReturn["DRBPERSETZV1"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZN1"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZV2"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZN2"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZV3"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZN3"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZV4"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZN4"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZV5"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZN5"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZV6"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZN6"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZV7"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZN7"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZV8"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZN8"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZV9"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZN9"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZV10"] = " ".PadRight(15 ); 
         dwReturn["DRBPERSETZN10"] = " ".PadRight(15 ); 
         dwReturn["DRBPSTATUS"] = " ".PadRight(1 ); 
         dwReturn["DRBPMNR"] = " ".PadRight(4 ); 
         dwReturn["DRBPMPAR1"] = " ".PadRight(40 ); 
         dwReturn["DRBPMPAR2"] = " ".PadRight(20 ); 
         dwReturn["DRBPMPAR3"] = " ".PadRight(80 ); 
         dwReturn["DRBPWARTEN"] = " ".PadRight(1 ); 
         dwReturn["DRBPFILLER"] = " ".PadRight(266 ); 
         dwReturn["DRBPNEUDAT"] = " ".PadRight(0 ); 
         dwReturn["DRBPNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["DRBPAENDAT"] = " ".PadRight(0 ); 
         dwReturn["DRBPAENBEN"] = " ".PadRight(8 ); 
         dwReturn["DRBPAENDZL"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapDRBPOS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveDRBPOS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryDRBPOS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapDRBPOS(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertDRBPOS(dwLocal, ITXDBVERSION);
            }
            UpdateDRBPOS(dwLocal);
        }
        public void InsertDRBPOS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO DRBPOS(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryDRBPOS(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM DRBPOS WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM DRBPOS  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "DRBPOS";
            Return = Result;
            return Return;
        }
        public void DeleteDRBPOS(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM DRBPOS   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateDRBPOS(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE DRBPOS SET "
                    +"DRBPMANDANT= :DRBPMANDANT,"
                    +"DRBPLFDNR= :DRBPLFDNR,"
                    +"DRBPPOS= :DRBPPOS,"
                    +"DRBPBEZ= :DRBPBEZ,"
                    +"DRBPPROG1= :DRBPPROG1,"
                    +"DRBPPROG2= :DRBPPROG2,"
                    +"DRBPDRBENID= :DRBPDRBENID,"
                    +"DRBPDRAUFTR= :DRBPDRAUFTR,"
                    +"DRBPAUFBENID= :DRBPAUFBENID,"
                    +"DRBPLASTAUF= :DRBPLASTAUF,"
                    +"DRBPABHLFDNR1= :DRBPABHLFDNR1,"
                    +"DRBPABHPOS1= :DRBPABHPOS1,"
                    +"DRBPABHLFDNR2= :DRBPABHLFDNR2,"
                    +"DRBPABHPOS2= :DRBPABHPOS2,"
                    +"DRBPABHLFDNR3= :DRBPABHLFDNR3,"
                    +"DRBPABHPOS3= :DRBPABHPOS3,"
                    +"DRBPABHLFDNR4= :DRBPABHLFDNR4,"
                    +"DRBPABHPOS4= :DRBPABHPOS4,"
                    +"DRBPABHLFDNR5= :DRBPABHLFDNR5,"
                    +"DRBPABHPOS5= :DRBPABHPOS5,"
                    +"DRBPLSTARTD= :DRBPLSTARTD,"
                    +"DRBPLSTARTZ= :DRBPLSTARTZ,"
                    +"DRBPLENDED= :DRBPLENDED,"
                    +"DRBPLENDEZ= :DRBPLENDEZ,"
                    +"DRBPERSETZV1= :DRBPERSETZV1,"
                    +"DRBPERSETZN1= :DRBPERSETZN1,"
                    +"DRBPERSETZV2= :DRBPERSETZV2,"
                    +"DRBPERSETZN2= :DRBPERSETZN2,"
                    +"DRBPERSETZV3= :DRBPERSETZV3,"
                    +"DRBPERSETZN3= :DRBPERSETZN3,"
                    +"DRBPERSETZV4= :DRBPERSETZV4,"
                    +"DRBPERSETZN4= :DRBPERSETZN4,"
                    +"DRBPERSETZV5= :DRBPERSETZV5,"
                    +"DRBPERSETZN5= :DRBPERSETZN5,"
                    +"DRBPERSETZV6= :DRBPERSETZV6,"
                    +"DRBPERSETZN6= :DRBPERSETZN6,"
                    +"DRBPERSETZV7= :DRBPERSETZV7,"
                    +"DRBPERSETZN7= :DRBPERSETZN7,"
                    +"DRBPERSETZV8= :DRBPERSETZV8,"
                    +"DRBPERSETZN8= :DRBPERSETZN8,"
                    +"DRBPERSETZV9= :DRBPERSETZV9,"
                    +"DRBPERSETZN9= :DRBPERSETZN9,"
                    +"DRBPERSETZV10= :DRBPERSETZV10,"
                    +"DRBPERSETZN10= :DRBPERSETZN10,"
                    +"DRBPSTATUS= :DRBPSTATUS,"
                    +"DRBPMNR= :DRBPMNR,"
                    +"DRBPMPAR1= :DRBPMPAR1,"
                    +"DRBPMPAR2= :DRBPMPAR2,"
                    +"DRBPMPAR3= :DRBPMPAR3,"
                    +"DRBPWARTEN= :DRBPWARTEN,"
                    +"DRBPFILLER= :DRBPFILLER,"
                    +"DRBPNEUDAT= :DRBPNEUDAT,"
                    +"DRBPNEUBEN= :DRBPNEUBEN,"
                    +"DRBPAENDAT= :DRBPAENDAT,"
                    +"DRBPAENBEN= :DRBPAENBEN,"
                    +"DRBPAENDZL= :DRBPAENDZL,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("DRBPMANDANT", OracleType.NVarChar).Value = dwData["DRBPMANDANT"].ToString(); 
          or1.Parameters.Add("DRBPLFDNR", OracleType.NVarChar).Value = dwData["DRBPLFDNR"].ToString(); 
          or1.Parameters.Add("DRBPPOS", OracleType.NVarChar).Value = dwData["DRBPPOS"].ToString(); 
          or1.Parameters.Add("DRBPBEZ", OracleType.NVarChar).Value = dwData["DRBPBEZ"].ToString(); 
          or1.Parameters.Add("DRBPPROG1", OracleType.NVarChar).Value = dwData["DRBPPROG1"].ToString(); 
          or1.Parameters.Add("DRBPPROG2", OracleType.NVarChar).Value = dwData["DRBPPROG2"].ToString(); 
          or1.Parameters.Add("DRBPDRBENID", OracleType.NVarChar).Value = dwData["DRBPDRBENID"].ToString(); 
          or1.Parameters.Add("DRBPDRAUFTR", OracleType.NVarChar).Value = dwData["DRBPDRAUFTR"].ToString(); 
          or1.Parameters.Add("DRBPAUFBENID", OracleType.NVarChar).Value = dwData["DRBPAUFBENID"].ToString(); 
          or1.Parameters.Add("DRBPLASTAUF", OracleType.NVarChar).Value = dwData["DRBPLASTAUF"].ToString(); 
          or1.Parameters.Add("DRBPABHLFDNR1", OracleType.NVarChar).Value = dwData["DRBPABHLFDNR1"].ToString(); 
          or1.Parameters.Add("DRBPABHPOS1", OracleType.NVarChar).Value = dwData["DRBPABHPOS1"].ToString(); 
          or1.Parameters.Add("DRBPABHLFDNR2", OracleType.NVarChar).Value = dwData["DRBPABHLFDNR2"].ToString(); 
          or1.Parameters.Add("DRBPABHPOS2", OracleType.NVarChar).Value = dwData["DRBPABHPOS2"].ToString(); 
          or1.Parameters.Add("DRBPABHLFDNR3", OracleType.NVarChar).Value = dwData["DRBPABHLFDNR3"].ToString(); 
          or1.Parameters.Add("DRBPABHPOS3", OracleType.NVarChar).Value = dwData["DRBPABHPOS3"].ToString(); 
          or1.Parameters.Add("DRBPABHLFDNR4", OracleType.NVarChar).Value = dwData["DRBPABHLFDNR4"].ToString(); 
          or1.Parameters.Add("DRBPABHPOS4", OracleType.NVarChar).Value = dwData["DRBPABHPOS4"].ToString(); 
          or1.Parameters.Add("DRBPABHLFDNR5", OracleType.NVarChar).Value = dwData["DRBPABHLFDNR5"].ToString(); 
          or1.Parameters.Add("DRBPABHPOS5", OracleType.NVarChar).Value = dwData["DRBPABHPOS5"].ToString(); 
          or1.Parameters.Add("DRBPLSTARTD", OracleType.NVarChar).Value = dwData["DRBPLSTARTD"].ToString(); 
          or1.Parameters.Add("DRBPLSTARTZ", OracleType.NVarChar).Value = dwData["DRBPLSTARTZ"].ToString(); 
          or1.Parameters.Add("DRBPLENDED", OracleType.NVarChar).Value = dwData["DRBPLENDED"].ToString(); 
          or1.Parameters.Add("DRBPLENDEZ", OracleType.NVarChar).Value = dwData["DRBPLENDEZ"].ToString(); 
          or1.Parameters.Add("DRBPERSETZV1", OracleType.NVarChar).Value = dwData["DRBPERSETZV1"].ToString(); 
          or1.Parameters.Add("DRBPERSETZN1", OracleType.NVarChar).Value = dwData["DRBPERSETZN1"].ToString(); 
          or1.Parameters.Add("DRBPERSETZV2", OracleType.NVarChar).Value = dwData["DRBPERSETZV2"].ToString(); 
          or1.Parameters.Add("DRBPERSETZN2", OracleType.NVarChar).Value = dwData["DRBPERSETZN2"].ToString(); 
          or1.Parameters.Add("DRBPERSETZV3", OracleType.NVarChar).Value = dwData["DRBPERSETZV3"].ToString(); 
          or1.Parameters.Add("DRBPERSETZN3", OracleType.NVarChar).Value = dwData["DRBPERSETZN3"].ToString(); 
          or1.Parameters.Add("DRBPERSETZV4", OracleType.NVarChar).Value = dwData["DRBPERSETZV4"].ToString(); 
          or1.Parameters.Add("DRBPERSETZN4", OracleType.NVarChar).Value = dwData["DRBPERSETZN4"].ToString(); 
          or1.Parameters.Add("DRBPERSETZV5", OracleType.NVarChar).Value = dwData["DRBPERSETZV5"].ToString(); 
          or1.Parameters.Add("DRBPERSETZN5", OracleType.NVarChar).Value = dwData["DRBPERSETZN5"].ToString(); 
          or1.Parameters.Add("DRBPERSETZV6", OracleType.NVarChar).Value = dwData["DRBPERSETZV6"].ToString(); 
          or1.Parameters.Add("DRBPERSETZN6", OracleType.NVarChar).Value = dwData["DRBPERSETZN6"].ToString(); 
          or1.Parameters.Add("DRBPERSETZV7", OracleType.NVarChar).Value = dwData["DRBPERSETZV7"].ToString(); 
          or1.Parameters.Add("DRBPERSETZN7", OracleType.NVarChar).Value = dwData["DRBPERSETZN7"].ToString(); 
          or1.Parameters.Add("DRBPERSETZV8", OracleType.NVarChar).Value = dwData["DRBPERSETZV8"].ToString(); 
          or1.Parameters.Add("DRBPERSETZN8", OracleType.NVarChar).Value = dwData["DRBPERSETZN8"].ToString(); 
          or1.Parameters.Add("DRBPERSETZV9", OracleType.NVarChar).Value = dwData["DRBPERSETZV9"].ToString(); 
          or1.Parameters.Add("DRBPERSETZN9", OracleType.NVarChar).Value = dwData["DRBPERSETZN9"].ToString(); 
          or1.Parameters.Add("DRBPERSETZV10", OracleType.NVarChar).Value = dwData["DRBPERSETZV10"].ToString(); 
          or1.Parameters.Add("DRBPERSETZN10", OracleType.NVarChar).Value = dwData["DRBPERSETZN10"].ToString(); 
          or1.Parameters.Add("DRBPSTATUS", OracleType.NVarChar).Value = dwData["DRBPSTATUS"].ToString(); 
          or1.Parameters.Add("DRBPMNR", OracleType.NVarChar).Value = dwData["DRBPMNR"].ToString(); 
          or1.Parameters.Add("DRBPMPAR1", OracleType.NVarChar).Value = dwData["DRBPMPAR1"].ToString(); 
          or1.Parameters.Add("DRBPMPAR2", OracleType.NVarChar).Value = dwData["DRBPMPAR2"].ToString(); 
          or1.Parameters.Add("DRBPMPAR3", OracleType.NVarChar).Value = dwData["DRBPMPAR3"].ToString(); 
          or1.Parameters.Add("DRBPWARTEN", OracleType.NVarChar).Value = dwData["DRBPWARTEN"].ToString(); 
          or1.Parameters.Add("DRBPFILLER", OracleType.NVarChar).Value = dwData["DRBPFILLER"].ToString(); 
          or1.Parameters.Add("DRBPNEUDAT", OracleType.NVarChar).Value = dwData["DRBPNEUDAT"].ToString(); 
          or1.Parameters.Add("DRBPNEUBEN", OracleType.NVarChar).Value = dwData["DRBPNEUBEN"].ToString(); 
          or1.Parameters.Add("DRBPAENDAT", OracleType.NVarChar).Value = dwData["DRBPAENDAT"].ToString(); 
          or1.Parameters.Add("DRBPAENBEN", OracleType.NVarChar).Value = dwData["DRBPAENBEN"].ToString(); 
          or1.Parameters.Add("DRBPAENDZL", OracleType.NVarChar).Value = dwData["DRBPAENDZL"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
